function PaiBanTab(str){
	//初始化表格
	$('#PaiBandg').datagrid({
	    url:'PaiBan',
	    queryParams:{
	    	Str:str
	    },
	    columns:[[
			{field:'KPRID',checkbox:true,width:60,title:'排班编号',align:'center'},
			{field:'CWASID',title:'所属考勤卡',width:100,align:'center'},
			{field:'DEPTNAME',title:'部门',width:100,align:'center'},
			{field:'TEMNAME',title:'班组',width:100,align:'center'},
			{field:'SHFNAME',title:'班次',width:100,align:'center'},
			{field:'SHFREM',title:'班次时间',width:180,align:'center'},
			{field:'EMPID',title:'员工id',width:100,align:'center',hidden:true},
			{field:'EMPNAME',title:'员工姓名',width:100,align:'center'},
			{field:'RSNREASON',title:'考勤原因',width:100,align:'center'},
			{field:'CWASREM',title:'备注',width:100,align:'center'},
			{field:'caozuo',fixed:false,width:100,formatter:operate_formatter,title:'操作',align:'center'}
		]],
	    toolbar:'#PaiBantb',
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15]
	});
}
function operate_formatter(value, row, index) {
	return "<button class='easyui-linkbutton' onclick='deletePB("+row.KPRID+")'>删除</button> ";
}

function PaiBanSS(value,name){
	PaiBanTab(value);
}

$(function(){
	PaiBanTab(null);
	
	//点击提交
	$("#updatePB").click(function(){
		var KaoQinKaId = $("#KaoQinKaId").val();
		
		var rows=$('#PaiBanRenYuandg').datagrid('getChecked');
		for(var i=0;i<rows.length;i++){
			$.ajax({
				url:"updatePBs",
				type:"post",
//				traditional:true,
				data:{"cwasid":KaoQinKaId,"EMPID":rows[i]["EMPID"]},
				success:function(data){
					$('#PaiBandg').datagrid('reload');
				}
			});
		}

		$.ajax({
			url:"updatePB",
			type:"post",
			data:{"cwasid":KaoQinKaId,"empidsl":rows.length},
			success:function(data){
				$('#PaiBandg').datagrid('reload');
			}
		});
		
//		var jsons = [];
//		for(var i=0;i<rows.length;i++){
//			jsons.push(rows[i]["EMPID"]);
//		}
//		$.ajax({
//			url:"updatePB1",
//			type:"post",
//			traditional:true,
//			data:{"cwasid":KaoQinKaId,"josns":jsons},
//			success:function(data){
//				$('#PaiBandg').datagrid('reload');
//			}
//		});
		
		//清空表单
		$("#RSNID").val("");
		$("#RSNREASON").val("");
		$("#RSNREM").val("");   
		
		$("#PaiBanwin").window("close");
	});
	
	$("#PaiBandel").click(function(){
		var rows=$('#PaiBandg').datagrid('getChecked');
		for(var i=0;i<rows.length;i++){
//			alert(rows[i]["KPRID"]);
			if(confirm("你确定删除选中的   "+rows.length+"   行目标嘛 ？")){
				deletePB(rows[i]["KPRID"]);
			}else{
				
			}
		}
	});
	
	//显示
	$("#PaiBanadd").click(function(){
		$("#RSNID").val("");
		$("#RSNREASON").val("");
		$("#RSNREM").val("");   
		$("#PaiBanwin").window("open");
		$('#KaoQinKaId').combobox({
			url:'KaoQinKa',
			valueField:'CWASID',
	        formatter:function(row){
	               row.TEMNAME = row.TEMNAME+"  考勤卡："+row.CWASID;
	               return row.TEMNAME;
	        },
	        onChange:function(){
	        	DeptEmp()
	        }
		});
	});
	
	
});

//删除方法
function deletePB(KPRID){
	deleteBG("deletePB","PaiBandg",{"kprid":KPRID});
}

function DeptEmp() {
	var cwasid = $("#KaoQinKaId").val();
	$('#PaiBanRenYuandg').datagrid({
	    url:'PBdeptemp',
	    queryParams:{
	    	cwasid:cwasid
	    }, 
	    columns:[[
			{field:'EMPID',checkbox:true,title:'员工id',width:1,align:'center'},
			{field:'EMPNAME',title:'未排班员工',width:1,align:'center'}
		]],
	});
}